<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue3-escook</title>
  <link rel="stylesheet" href="./lib/style.css">
  <script type="importmap">
    {
      "imports" : {
        "vue": "./lib/vue-3.4.29.js"
      }
    }
  </script>
  <script type="module">
    import { createApp, ref, watch, watchEffect } from 'vue'

    const app = createApp({
      setup() {
        const title = ref('哇哈哈')
        const suffix = ref('dev')

        watch(title, (newTitle, oldTitle) => {
          document.title = newTitle + '-' + suffix.value
        }, {
          immediate: true
        })

        // watchEffect 所指定的副作用函数，上来就会默认执行一次，
        // 目的：是为了收集“响应式数据”和“副作用函数”的依赖关系
        // watchEffect(() => {
        //   console.log('ok')
        //   document.title = title.value + '-' + suffix.value
        // })

        return { title, suffix }
      }
    })

    app.mount('#app')
  </script>
</head>

<body>
  <div id="app">
    <div>
      <span>标题：</span>
      <input type="text" v-model="title">
    </div>
    <div>
      <span>后缀：</span>
      <input type="text" v-model="suffix">
    </div>
  </div>
</body>

</html>